# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Stefan Wagner <stw@bit-strickerei.de>
# Maintainer: Valery Kartel <valery.kartel@gmail.com>
pkgname=opendkim
pkgver=2.11.0
subrel="Beta2"
pkgrel=3
pkgdesc="DKIM signing and verifying filter for MTAs"
url="http://www.opendkim.org"
arch="all"
license="custom"
makedepends="openssl-dev>3 libmilter-dev automake autoconf libtool"
pkgusers="opendkim"
pkggroups="opendkim"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc $pkgname-libs $pkgname-utils"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/trusteddomainproject/OpenDKIM/archive/refs/tags/$pkgver-$subrel.tar.gz
	$pkgname.confd
	$pkgname.initd"
builddir="$srcdir/OpenDKIM-$pkgver-$subrel"

# secfixes:
#   0:
#     - CVE-2020-35766

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc/$pkgname
	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -d "$pkgdir"/etc/$pkgname
	install -dm750 -g mail "$pkgdir"/var/db/dkim
	cat "$pkgdir"/usr/share/doc/$pkgname/$pkgname.conf.simple | sed \
		-e '/^Socket.*$/a#Socket\t\t\tlocal:opendkim.sock' \
		-e '1s~.*~BaseDirectory\t\t/run/opendkim~' \
		> "$pkgdir"/etc/$pkgname/$pkgname.conf
	install -d "$pkgdir"/usr/share/licenses/$pkgname;
	mv "$pkgdir"/usr/share/doc/$pkgname/LICENSE* \
		"$pkgdir"/usr/share/licenses/$pkgname
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

utils() {
	pkgdesc="$pkgdesc (key and zone utilities)"
	depends="$pkgname openssl perl"
	install -d "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/sbin/$pkgname-* "$subpkgdir"/usr/bin
	rm -fr "$pkgdir"/usr/lib
}

sha512sums="
6574755db70b4959a9d6f9f854a889f3905057b8563690571a3a13b6215658b9c5ea365fa34316208c71561eefd9bdcacbccea420557d5a76a7744e98f095980  opendkim-2.11.0.tar.gz
1dd6ed6e4efd93463f8eeb4603e72cf3a77f0a70117164a34b45bf0d2f45d4520b62c86696f7d180cff61a73201253c1ff875efdcd5317d631118776db665ea1  opendkim.confd
a3c3b4d4af875903aec1ae9f565113dc6b10fb0c5c45df96f043735de9be772e6d2fca812ce2bd51f9759f4a7c18ac5ced62a7b5530924edd0981250cb88f91f  opendkim.initd
"
